package com.devshephard.rpcframework.rpc.controller;

import com.devshephard.rpcframework.rpc.enums.RequestType;
import com.devshephard.rpcframework.rpc.factory.base.RpcBaseCustomFactory;
import com.devshephard.rpcframework.rpc.service.testservice.RpcService;
import com.devshephard.rpcframework.rpc.service.testservice.TcpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;

@RestController
@Slf4j
public class TestRpcController  {

    @Autowired
    RpcBaseCustomFactory rpcBaseCustomFactory;

    @Autowired
    RpcService rpcService;

    @Autowired
    TcpService tcpService;


    @GetMapping("/testConnectCheck01")
    @ResponseBody
    public void testConnect(HttpServletResponse response) throws Exception {

        rpcService.getTestString("3");


        /*RpcService myRpcService = (RpcService) rpcBaseCustomFactory.rpcServiceProxyBuilderRequest(RpcService.class, RequestType.HTTP.getDesc());

        myRpcService.getTestString("1", response);
        System.out.println("tomcat-nio线程执行完毕 check01");*/

        return;
    }

    @GetMapping("/testConnectCheck02")
    @ResponseBody
    public void testConnect2(HttpServletResponse response) throws Exception {

        RpcService myRpcService = (RpcService) rpcBaseCustomFactory.rpcServiceProxyBuilder(RpcService.class);
        myRpcService.getTestString("3");
        System.out.println("tomcat-nio线程执行完毕 check02");

        return;
    }

    @GetMapping("/testConnectCheck04")
    @ResponseBody
    public String testConnect04() throws Exception {

        TcpService service = (TcpService) rpcBaseCustomFactory
                .rpcServiceProxyBuilderRequest(TcpService.class, RequestType.TCP.getDesc());
        String zhangsan = service.sayHello("zhangsan");
        System.out.println("tomcat-nio线程执行完毕 check04");

        return zhangsan;
    }

    @GetMapping("/testConnectCheck05")
    @ResponseBody
    public String testConnectCheck05() throws Exception {

        String zhangsan = tcpService.sayHello("zhangsan");
        System.out.println("tomcat-nio线程执行完毕 check04");

        return zhangsan;
    }

  /*  @Autowired
    MyRpcService myRpcService;

    @GetMapping("/testBeanProxy")
    @ResponseBody
    public void testBeanProxy() throws Exception {

        System.out.println(myRpcService);

    }*/
}
